import Api from '../Api'
import {controller, get, post} from "../../../decorator/decorator";
import {SMS_SEND,EXIST,AREA,EDIT_PASSWORD,CLOUDUPLOADURL,SUBMIT_COMPLAIN} from "../../../common/config/url";
import UUID from 'uuid-js'
import $ from 'jquery'
import {ABNORMAL} from "../../../common/config/code";
@controller('')
class Base extends Api{
  constructor(){
    super(Base);
  }
  @get(SMS_SEND)
  async smsSend(params){
    return await this.common(params)
  }
  @get(EXIST,false)
  async exist(params){
    return await this.common(params)
  }
  @get(AREA,false)
  async area(params){
    return await this.common(params)
  }
  @post(EDIT_PASSWORD)
  async editPassword(params){
    return await this.common(params)
  }
  @get(CLOUDUPLOADURL)
  async clouduplLoadUrl(params){
    try{
      let file=params.data;
      let uuid=UUID.create().hex
      params.params={
        key:uuid
      }
      delete params.data
      let data=await this.common(params);
      return new Promise((resolve,reject)=>{
        if(data.data){
          $.ajax({
            url: data.data,
            type: "PUT",
            cache: false,
            contentType: false,// 告诉jQuery不要去设置Content-Type请求头
            processData: false,// 告诉jQuery不要去处理发送的数据
            data: file,
            success: function () {
              params.success(uuid)
              resolve(uuid)

            },
            error: function (err) {
              reject(err)
            }
          });
          // let config={
          //   baseURL:'',
          //   url:data.data,
          //   method:'put',
          //   data:file,
          //   headers:{
          //     'Content-Type':''
          //   },
          //   error:()=>{
          //
          //     console.info(typeof uuid)
          //     params.success(uuid)
          //   }
          // }
          // return await this.common(config)
        }else{
          resolve(null)
        }
      })

    }catch (e) {
      console.info(e)
    }

  }

  @post(SUBMIT_COMPLAIN)
  async submitComplain(params){
    return await this.common(params)
  }
}
export default new Base()
